package com.cat.enumerate;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/splitting-a-string-into-descending-consecutive-values/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/20 21:43
 * @since JDK17
 */

public class Solution08 {
    public boolean splitString(String s) {
        char[] arr = s.toCharArray();
        int n = arr.length;
        for (int len = 0; len < n; len++) { // 枚举第一个数字是几位数
            int last = 0, i = 0, m = ((int) Math.pow(10, len)), cur;
            while (last <= m && i < n - 1) {
                last = last * 10 + arr[i++] - '0';
            }
            cur = 0;
            boolean flag = false;
            for (int j = i; j < n; j++) {
                if (cur < last - 1) {   // 怎么保证最后一段是last - 1 ?
                    cur = cur * 10 + arr[j] - '0';
                    flag = false;
                } else if (cur == last - 1) {   //
                    last--;
                    cur = 0;
                    flag = true;
                } else {
                    break;
                }
            }
            if (flag) {
                return true;
            }
        }

        return false;
    }
}
